from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-05 14:26:34.131453
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 05, Oct, 2022
Time: 14:26:42
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.6112
Nobs: 800.000 HQIC: -50.9358
Log likelihood: 10328.9 FPE: 6.17944e-23
AIC: -51.1382 Det(Omega_mle): 5.52578e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297951 0.052936 5.629 0.000
L1.Burgenland 0.108951 0.035586 3.062 0.002
L1.Kärnten -0.106426 0.018943 -5.618 0.000
L1.Niederösterreich 0.209824 0.074414 2.820 0.005
L1.Oberösterreich 0.101532 0.071432 1.421 0.155
L1.Salzburg 0.252011 0.037950 6.641 0.000
L1.Steiermark 0.037694 0.049654 0.759 0.448
L1.Tirol 0.106323 0.040248 2.642 0.008
L1.Vorarlberg -0.059200 0.034608 -1.711 0.087
L1.Wien 0.055820 0.063812 0.875 0.382
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063866 0.109622 0.583 0.560
L1.Burgenland -0.033478 0.073693 -0.454 0.650
L1.Kärnten 0.047804 0.039229 1.219 0.223
L1.Niederösterreich -0.171579 0.154100 -1.113 0.266
L1.Oberösterreich 0.384687 0.147926 2.601 0.009
L1.Salzburg 0.287606 0.078590 3.660 0.000
L1.Steiermark 0.106208 0.102827 1.033 0.302
L1.Tirol 0.313585 0.083349 3.762 0.000
L1.Vorarlberg 0.025136 0.071667 0.351 0.726
L1.Wien -0.017155 0.132146 -0.130 0.897
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190010 0.027184 6.990 0.000
L1.Burgenland 0.090092 0.018274 4.930 0.000
L1.Kärnten -0.008445 0.009728 -0.868 0.385
L1.Niederösterreich 0.264277 0.038213 6.916 0.000
L1.Oberösterreich 0.126840 0.036682 3.458 0.001
L1.Salzburg 0.047552 0.019488 2.440 0.015
L1.Steiermark 0.016871 0.025499 0.662 0.508
L1.Tirol 0.094208 0.020669 4.558 0.000
L1.Vorarlberg 0.059247 0.017772 3.334 0.001
L1.Wien 0.120404 0.032769 3.674 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109319 0.027835 3.927 0.000
L1.Burgenland 0.044515 0.018712 2.379 0.017
L1.Kärnten -0.016115 0.009961 -1.618 0.106
L1.Niederösterreich 0.193645 0.039129 4.949 0.000
L1.Oberösterreich 0.293434 0.037561 7.812 0.000
L1.Salzburg 0.115362 0.019956 5.781 0.000
L1.Steiermark 0.100146 0.026110 3.836 0.000
L1.Tirol 0.116297 0.021164 5.495 0.000
L1.Vorarlberg 0.070724 0.018198 3.886 0.000
L1.Wien -0.027633 0.033554 -0.824 0.410
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128996 0.050484 2.555 0.011
L1.Burgenland -0.051443 0.033937 -1.516 0.130
L1.Kärnten -0.040221 0.018066 -2.226 0.026
L1.Niederösterreich 0.170983 0.070967 2.409 0.016
L1.Oberösterreich 0.137913 0.068124 2.024 0.043
L1.Salzburg 0.286064 0.036193 7.904 0.000
L1.Steiermark 0.034570 0.047354 0.730 0.465
L1.Tirol 0.163896 0.038384 4.270 0.000
L1.Vorarlberg 0.104009 0.033005 3.151 0.002
L1.Wien 0.067527 0.060857 1.110 0.267
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060507 0.040039 1.511 0.131
L1.Burgenland 0.038201 0.026916 1.419 0.156
L1.Kärnten 0.050634 0.014328 3.534 0.000
L1.Niederösterreich 0.225304 0.056284 4.003 0.000
L1.Oberösterreich 0.282155 0.054029 5.222 0.000
L1.Salzburg 0.050637 0.028705 1.764 0.078
L1.Steiermark -0.006582 0.037557 -0.175 0.861
L1.Tirol 0.149854 0.030443 4.922 0.000
L1.Vorarlberg 0.071207 0.026176 2.720 0.007
L1.Wien 0.079019 0.048266 1.637 0.102
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.178714 0.047865 3.734 0.000
L1.Burgenland -0.005885 0.032177 -0.183 0.855
L1.Kärnten -0.061049 0.017129 -3.564 0.000
L1.Niederösterreich -0.083054 0.067286 -1.234 0.217
L1.Oberösterreich 0.192703 0.064590 2.983 0.003
L1.Salzburg 0.056759 0.034315 1.654 0.098
L1.Steiermark 0.230908 0.044898 5.143 0.000
L1.Tirol 0.493492 0.036393 13.560 0.000
L1.Vorarlberg 0.049390 0.031293 1.578 0.114
L1.Wien -0.049596 0.057700 -0.860 0.390
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161613 0.054948 2.941 0.003
L1.Burgenland -0.011049 0.036938 -0.299 0.765
L1.Kärnten 0.066012 0.019663 3.357 0.001
L1.Niederösterreich 0.200966 0.077243 2.602 0.009
L1.Oberösterreich -0.061573 0.074148 -0.830 0.406
L1.Salzburg 0.215636 0.039393 5.474 0.000
L1.Steiermark 0.114031 0.051542 2.212 0.027
L1.Tirol 0.076667 0.041779 1.835 0.066
L1.Vorarlberg 0.124343 0.035923 3.461 0.001
L1.Wien 0.115528 0.066238 1.744 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.354331 0.031948 11.091 0.000
L1.Burgenland 0.006095 0.021477 0.284 0.777
L1.Kärnten -0.023510 0.011433 -2.056 0.040
L1.Niederösterreich 0.223845 0.044910 4.984 0.000
L1.Oberösterreich 0.176296 0.043111 4.089 0.000
L1.Salzburg 0.047205 0.022904 2.061 0.039
L1.Steiermark -0.018200 0.029968 -0.607 0.544
L1.Tirol 0.108567 0.024291 4.469 0.000
L1.Vorarlberg 0.073260 0.020886 3.508 0.000
L1.Wien 0.053408 0.038512 1.387 0.166
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041097 0.152366 0.190689 0.157115 0.125362 0.113779 0.065895 0.226388
Kärnten 0.041097 1.000000 -0.002574 0.129648 0.041387 0.096182 0.429642 -0.053167 0.101428
Niederösterreich 0.152366 -0.002574 1.000000 0.337239 0.155039 0.300791 0.110815 0.183563 0.327449
Oberösterreich 0.190689 0.129648 0.337239 1.000000 0.232135 0.333217 0.172329 0.172359 0.263738
Salzburg 0.157115 0.041387 0.155039 0.232135 1.000000 0.146558 0.126746 0.148975 0.136371
Steiermark 0.125362 0.096182 0.300791 0.333217 0.146558 1.000000 0.153430 0.140838 0.080763
Tirol 0.113779 0.429642 0.110815 0.172329 0.126746 0.153430 1.000000 0.114800 0.155274
Vorarlberg 0.065895 -0.053167 0.183563 0.172359 0.148975 0.140838 0.114800 1.000000 0.007307
Wien 0.226388 0.101428 0.327449 0.263738 0.136371 0.080763 0.155274 0.007307 1.000000